<template>
  <div>
    <Common-head title="商品列表" />
    <div class="wrap">
      <!-- 筛选 -->
      <div class="filter">
        <div @click="orderBysale" :class="['order','sale',{active: order.orderBy === 'sale'}]">
          <span>销量</span>
          <div :class="['anle', 'up',{active: order.orderBy === 'sale' && order.upDown === 'up'}]"></div>
          <div
            :class="['anle', 'down',{active: order.orderBy === 'sale' && order.upDown === 'down'}]"
          ></div>
        </div>
        <div @click="orderByprice" :class="['order','price',{active: order.orderBy === 'price'}]">
          <span>价格</span>
          <div :class="['anle', 'up',{active: order.orderBy === 'price' && order.upDown === 'up'}]"></div>
          <div
            :class="['anle', 'down',{active: order.orderBy === 'price' && order.upDown === 'down'}]"
          ></div>
        </div>
      </div>
      <!-- /筛选 -->
      <!-- 商品列表 -->
      <div class="recommed">
        <div class="recommend-items">
          <div class="item" v-for="item in items" :key="item.id">
            <img class="item-pic" :src="item.pic" alt />
            <div class="item-info">
              <h5>{{item.name}}</h5>
              <p class="item-p0">{{item.tags| subStr }}</p>
              <p class="item-p">{{item.characteristic | subStr }}</p>
              <p class="item-p1">{{item.purchaseNotes}}</p>
              <div class="item-action">
                <p class="price">{{item.minPrice | currency('￥') }}</p>
                <van-icon color="#FF734C" class-prefix="icon" name="gouwuchekong"></van-icon>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- /商品列表 -->
    </div>
  </div>
</template>

<script>
import CommonHead from '@components/CommonHead'
import { commodity } from '@api'
import { currency, subStr } from '@/filters'
export default {
  data () {
    return {
      order: {
        orderBy: 'price',
        upDown: 'up'
      },
      items: [],
      orderBy: 'ordersDown'
    }
  },
  created () {
    this.commodity()
  },
  methods: {
    commodity () {
      commodity({
        categoryId: this.$route.query.cate_id,
        orderBy: this.orderBy
      }).then(res => {
        if (res.data.code === 0) {
          this.items = res.data.data
        }
      })
    },
    orderBysale () {
      if (this.order.orderBy === 'price') {
        this.order.orderBy = 'sale'
        this.order.upDown = 'down'
        this.orderBy = 'ordersDown'
      } else {
        if (this.order.upDown === 'up') {
          this.order.upDown = 'down'
          this.orderBy = 'ordersDown'
        } else {
          this.order.upDown = 'up'
          this.orderBy = 'ordersUp'
        }
      }
      this.commodity()
    },
    orderByprice () {
      if (this.order.orderBy === 'sale') {
        this.order.orderBy = 'price'
        this.order.upDown = 'down'
        this.orderBy = 'priceDown'
      } else {
        if (this.order.upDown === 'up') {
          this.order.upDown = 'down'
          this.orderBy = 'priceDown'
        } else {
          this.order.upDown = 'up'
          this.orderBy = 'priceUp'
        }
      }
      this.commodity()
    }
  },
  filters: {
    currency,
    subStr
  },
  components: {
    CommonHead
  }
}
</script>

<style lang="scss" scoped>
.wrap {
  margin-top: 44px;
  .filter {
    height: 44px;
    width: 100%;
    display: flex;
    background-color: #fff;
    align-items: center;
    justify-content: space-around;
    .order {
      position: relative;
      &.active {
        color: #ff734c;
      }
      .anle {
        width: 0;
        height: 0;
        border: 6px solid transparent;
        position: absolute;
        right: -16px;
        &.up {
          border-bottom-color: #333;
          top: -2px;
          &.active {
            border-bottom-color: #ff734c;
          }
        }
        &.down {
          border-top-color: #333;
          top: 12px;
          &.active {
            border-top-color: #ff734c;
          }
        }
      }
    }
  }
}
.recommend-items {
  .item {
    border-radius: 10px;
    height: 185px;
    background-color: #fff;
    display: flex;
    margin-bottom: 12px;
    .item-pic {
      border-radius: 10px;
      width: 170px;
      height: 185px;
    }
    /deep/.item-info {
      flex: 1;
      height: 185px;
      display: flex;
      flex-direction: column;
      padding: 10px;
      h5 {
        font-size: 14px;
        color: #232628;
        line-height: 20px;
        margin-bottom: 10px;
      }
      .item-p0 {
        font-size: 14px;
        line-height: 20px;
        margin-bottom: 10px;
      }
      .item-p {
        font-size: 12px;
        line-height: 20px;
        color: #666;
        margin-bottom: 5px;
      }
      .item-p1 {
        font-size: 12px;
        line-height: 20px;
        border-radius: 10px;
        // border: 1px solid red;
        background-color: #fff0ec;
        color: red;
      }
      .item-action {
        display: flex;
        height: 50px;
        align-items: center;
        justify-content: space-between;
        .price {
          font-size: 16px;
          font-weight: 600;
        }
      }
    }
  }
}
</style>
